package mhnm.projectgoodmorning;

import java.io.IOException;
import java.io.OutputStream;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

public class RemoteClickListener implements OnClickListener {
	private Context context;
	
	private BTController bTController;
	private String command;
	
	public RemoteClickListener( Context context, BTController bTController, String command ) {
		this.context = context;
		
		this.bTController = bTController;
		this.command = command;
	}
	
	@Override
	public void onClick(View v) {
		if( bTController != null ) {
			try {
				if( bTController.isConnected() ) {
					OutputStream outputStream = bTController.getOutputStream();
					outputStream.write( command.getBytes("ASCII") );
					outputStream.flush();
				} else {
					Toast.makeText( context, "Not connected.", Toast.LENGTH_SHORT).show();
				}
			} catch (IOException e) {
				Toast.makeText( context, "Connection problems. Please try to reconnect.", Toast.LENGTH_SHORT).show();
			}
		}
	}

}

